package Evaluation;

import java.util.*;


public class FailurePurity {
	
	ClusterResultMap crm;
	TestCaseDivide tcd;
	
	public FailurePurity(ClusterResultMap crm, TestCaseDivide tcd){
		this.crm = crm;
		this.tcd = tcd;
	}
	
	public double getPurityFailureCount(){
		double count = 0;
		Map<Integer, ArrayList<Integer>> m = crm.getMap();
		for(int i: m.keySet()){
			List<Integer> l = m.get(i);
			if(judgePurity(l))
				count += l.size();
		}
		return count;
		
	}
	
	public boolean judgePurity(List<Integer> l){
		int totalFailureNum = l.size();
		int count = 0;
		for(int i: l){
			if(tcd.getFailureIndexCluster().contains(i)){
				count++;
			}
		}
		if(count == totalFailureNum)
			return true;
		else
			return false;
	}
	
	public double calculateFP(){
		return getPurityFailureCount()/tcd.getFailureIndexCluster().size();
	}
}
